package org.example.node;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author liyishan
 * @date 2024/6/13 10:16
 * @apiNote
 */

public class Test00559MaxDepth {
    public static void main(String[] args) {
        Node root = new Node(1);
        root.children = new LinkedList<>();
        root.children.add(new Node(3));
        root.children.add(new Node(2));
        root.children.add(new Node(4));
        root.children.get(0).children = new LinkedList<>();
        root.children.get(0).children.add(new Node(5));
        root.children.get(0).children.add(new Node(6));
        System.out.println(maxDepth1(root));
    }

    public int maxDepth(Node root) {
        if (root == null) {
            return 0;
        }
        int maxChildrenDepth = 0;
        for (Node child : root.children) {
            maxChildrenDepth = Math.max(maxChildrenDepth, maxDepth(child));
        }
        return maxChildrenDepth + 1;
    }

    public static int maxDepth1(Node root) {
        if (root == null){
            return 0;
        }
        Queue<Node> queue = new LinkedList<Node>();
        queue.offer(root);
        int ans = 0;
        while(!queue.isEmpty()){
            int size = queue.size();
            while(size > 0){
                Node node = queue.poll();
                List<Node> children = node.children;
                for(Node child : children){
                    queue.offer(child);
                }
                size--;
            }
            ans++;
        }
        return ans;
    }
}
